package com.mgang.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.plugin.spring.SpringPlugin;
import com.jfinal.render.ViewType;
import com.mgang.model.User;
import com.mgang.util.log.MgLog;
import com.mgang.web.controller.HelloJFinalController;
import com.mgang.web.controller.MysqlController;
import com.mgang.web.controller.ParamController;
/**
 * 
 * @author meigang 2014-12-9 18:34
 * JFinalDemo项目的JFinal的配置类
 *
 */
public class JFinalDemoConfig extends JFinalConfig{
	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		//配置项目根请求
		me.add("/", HelloJFinalController.class);
		me.add("/param", ParamController.class);
		me.add("/mysql/user", MysqlController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		//加入ehcache缓存
		me.add(new EhCachePlugin());
		//加入spring容器
		me.add(new SpringPlugin());
		
		loadPropertyFile("db.properties");
		DruidPlugin dp = new DruidPlugin(getProperty("mysql.url"), 
						getProperty("mysql.username"), 
						getProperty("mysql.password"), 
						getProperty("mysql.driver"));
		/*dp.addFilter(new MergeStatFilter());
		dp.setMaxActive(150);
		WallFilter wall = new WallFilter();
		wall.setDbType(getProperty("dbType"));
		dp.addFilter(wall);*/
		me.add(dp);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		arp.addMapping("t_user",User.class);
		MgLog.log.info("添加User Model");
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

}
